package org.examples.java.lang;

import org.junit.Test;

public class ErrorsTest {

    //Thrown when an application tries to call an abstract method.
    //@Test(expected = AbstractMethodError.class)
    public void testAbstractMethodError() {
        new AbstractMethodError();
        new AbstractMethodError("");
    }

    //Thrown to indicate that an assertion has failed.
    //@Test(expected = AssertionError.class)
    public void testAssertionError() {
        new AssertionError();
        new AssertionError("");
    }

    //Thrown when a circularity has been detected while initializing a class.
    //@Test(expected = ClassCircularityError.class)
    public void testClassCircularityError() {
        new ClassCircularityError();
        new ClassCircularityError("");
    }

    //Thrown when the Java Virtual Machine attempts to read a class file and determines that the file is malformed or otherwise cannot be interpreted as a class file.
    // @Test(expected = ClassFormatError.class)
    public void testClassFormatError() {
        new ClassFormatError();
        new ClassFormatError("");
    }

    //An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.
    @Test(expected = Error.class)
    public void testError() {
        new Error();
        new Error("");

        throw new Error();
    }

    private static class ExceptionInInitializerErrorProducer {
        static {
            int i = 9 / 0;
        }

    }

    //Signals that an unexpected exception has occurred in a static initializer.
    @Test(expected = ExceptionInInitializerError.class)
    public void testExceptionInInitializerError() {
        new ExceptionInInitializerError();
        new ExceptionInInitializerError("");
        new ExceptionInInitializerError(new Exception());
        new ExceptionInInitializerError(new Exception());

        new ExceptionInInitializerErrorProducer();
    }

    //Thrown if an application attempts to access or modify a field, or to call a method that it does not have access to.
    //@Test(expected = IllegalAccessError.class)
    public void testIllegalAccessError() throws Exception {
        new IllegalAccessError();
        new IllegalAccessError("");
    }

    //Thrown when an incompatible class change has occurred to some class definition.
    //@Test(expected = IncompatibleClassChangeError.class)
    public void testIncompatibleClassChangeError() {
        new IncompatibleClassChangeError();
        new IncompatibleClassChangeError("");
    }

    //Thrown when an application tries to use the Java new construct to instantiate an abstract class or an interface.
    //@Test(expected = InstantiationError.class)
    public void testInstantiationError() throws InstantiationException, IllegalAccessException {
        new InstantiationError();
        new InstantiationError("");
    }

    //Thrown to indicate some unexpected internal error has occurred in the Java Virtual Machine.
    //@Test(expected = InternalError.class)
    public void testInternalError() {
        new InternalError();
        new InternalError("");
    }

    //Subclasses of LinkageError indicate that a class has some dependency on another class; however, the latter class has incompatibly changed after the compilation of the former class.
    //@Test(expected = LinkageError.class)
    public void testLinkageError() {
        new LinkageError();
        new LinkageError("");
    }

    //Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
    //@Test(expected = NoClassDefFoundError.class)
    public void testNoClassDefFoundError() {
        new NoClassDefFoundError();
        new NoClassDefFoundError("");
    }

    //Thrown if an application tries to access or modify a specified field of an object, and that object no longer has that field.
    //@Test(expected = NoSuchFieldError.class)
    public void testNoSuchFieldError() {
        new NoSuchFieldError();
        new NoSuchFieldError("");
    }

    //Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method.
    //@Test(expected = NoSuchMethodError.class)
    public void testNoSuchMethodError() {
        new NoSuchMethodError();
        new NoSuchMethodError("");
    }

    //Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.
    //@Test(expected = OutOfMemoryError.class)
    public void testOutOfMemoryError() {
        new OutOfMemoryError();
        new OutOfMemoryError("");
    }

    //Thrown when a stack overflow occurs because an application recurses too deeply.
    //@Test(expected = StackOverflowError.class)
    public void testStackOverflowError() {
        new StackOverflowError();
        new StackOverflowError("");
    }

    //An instance of ThreadDeath is thrown in the victim thread when the stop method with zero arguments in class Thread is called.
    //@Test(expected = ThreadDeath.class)
    public void testThreadDeath() {
        new ThreadDeath();
    }

    //Thrown when an unknown but serious exception has occurred in the Java Virtual Machine.
    //@Test(expected = UnknownError.class)
    public void testUnknownError() {
        new UnknownError();
        new UnknownError("");
    }

    //Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.
    //@Test(expected = UnsatisfiedLinkError.class)
    public void testUnsatisfiedLinkError() {
        new UnsatisfiedLinkError();
        new UnsatisfiedLinkError("");
    }

    //Thrown when the Java Virtual Machine attempts to read a class file and determines that the major and minor version numbers in the file are not supported.
    //@Test(expected = UnsupportedClassVersionError.class)
    public void testUnsupportedClassVersionError() {
        new UnsupportedClassVersionError();
        new UnsupportedClassVersionError("");
    }

    //Thrown when the "verifier" detects that a class file, though well formed, contains some sort of internal inconsistency or security problem.
    //@Test(expected = VerifyError.class)
    public void testVerifyError() {
        new VerifyError();
        new VerifyError("");
    }

    //Thrown to indicate that the Java Virtual Machine is broken or has run out of resources necessary for it to continue operating.
    @Test(expected = VirtualMachineError.class)
    public void testVirtualMachineError() {
        throw new OutOfMemoryError();
    }

}
